package Negocio;

import Datos.DBModelo;
import Datos.DBService;
import Entidades.Modelo;
import Entidades.Service;
import Interfaces.IService;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;


public class DAOService implements IService {

    DBService a = new DBService();
    DBModelo h=new DBModelo();
    public DefaultTableModel modelo = new DefaultTableModel();
    ArrayList<Service> al = a.ListaService();

    @Override
    public boolean IngresaService(Service nodo) {
        return a.IngresaService(nodo);
    }

    @Override
    public boolean ModificaService(Service nodo) {
        return a.ModificaService(nodo);
    }

    @Override
    public boolean EliminaService(int IDService) {
       return a.EliminaService(IDService);
    }

    @Override
    public ArrayList<Service> ListaService() {
        return a.ListaService();
    }

    @Override
    public DefaultTableModel ModeloService() {
         modelo = new DefaultTableModel();
        modelo = new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{
                    "id","Nombre","ID de  Modelo","Kms Requeridos","Precio"
                }){boolean[] canEdit = new boolean [] {
                false, true, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }};
        int i = 0;
        while (i < al.size()) {
         String id=Integer.toString(al.get(i).getIDService());
         String idM=Integer.toString(al.get(i).getIDModelo());
         String kms=Integer.toString(al.get(i).getKmsRequeridos());
         String precio=Integer.toString(al.get(i).getPrecio());
            String[] nombre2 = {id,al.get(i).getNombre(),idM,kms,precio};
         System.out.println();
            modelo.addRow(nombre2);
            i++;
        }
        //System.out.println(al.get(0).getIDColor());
        return modelo;        
        
    }
    public DefaultComboBoxModel cargo() {
        int x = 0;
        ArrayList<Modelo> j =h.ListaModelo();
        String[] datos1 = new String[j.size()];
        while (x < j.size()) {
              
            datos1[x] = Integer.toString(j.get(x).getIDModelo());;
            
            x++;
        }

        DefaultComboBoxModel model = new DefaultComboBoxModel(datos1);

        return model;
    }
    
}
